# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=jupyter_server
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.1.0
pkgrel=1
pkgdesc='Provides backend for core services, APIs and REST endpoints to Jupyter web application (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/jupyter-server/jupyter_server'
license=('spdx:BSD-3-Clause')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-anyio
    ${MINGW_PACKAGE_PREFIX}-python-argon2_cffi
    ${MINGW_PACKAGE_PREFIX}-python-jinja
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_client
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-server-terminals
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbformat
    ${MINGW_PACKAGE_PREFIX}-python-packaging
    ${MINGW_PACKAGE_PREFIX}-python-prometheus-client
    ${MINGW_PACKAGE_PREFIX}-python-pywinpty
    ${MINGW_PACKAGE_PREFIX}-python-pyzmq
    ${MINGW_PACKAGE_PREFIX}-python-send2trash
    ${MINGW_PACKAGE_PREFIX}-python-terminado
    ${MINGW_PACKAGE_PREFIX}-python-tornado
    ${MINGW_PACKAGE_PREFIX}-python-traitlets
    ${MINGW_PACKAGE_PREFIX}-python-websocket-client
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-events)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-hatchling
    ${MINGW_PACKAGE_PREFIX}-python-hatch-jupyter-builder)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('efaae5e4f0d5f22c7f2f2dc848635036ee74a2df02abed52d30d9d95121ad382')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 "COPYING.md" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
